package com.rw.engine.frequency.interceptor;

import com.rw.tool.util.cache.CacheHashMap;

import java.util.concurrent.TimeUnit;

/**
 * 默认的频率缓存器
 */
public class DefaultFrequencyCache implements FrequencyCache {
    private final CacheHashMap<String, Integer> cacheHashMap = new CacheHashMap<>();

    @Override
    public Integer getValue(String token) {
        return cacheHashMap.get(token);
    }

    @Override
    public void setValue(String token, int value, long survivalTime, TimeUnit timeUnit) {
        cacheHashMap.put(token, value, survivalTime, timeUnit);
    }

    @Override
    public void setValue(String token, int value) {
        cacheHashMap.replace(token, value);
    }
}